package com.restkeeper.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.restkeeper.utils.Snowflake;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;

/**
 * 通用字段处理
 */
@Component
public class GeneralMetaObjectHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		try {
			Snowflake snowflake=new Snowflake(1,1);
			setFieldValByName("id",snowflake.nextId(),metaObject);
//			setFieldValByName("create_time",new Date(),metaObject);
//			setFieldValByName("update_time",new Date(),metaObject);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		try {
			setFieldValByName("update_time",new Date(),metaObject);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


}
